// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import FastClick from 'fastclick'
import router from './router'
import App from './App'
import store from './store/index.js'
import vueWechatTitle from 'vue-wechat-title'


import 'vue-croppa/dist/vue-croppa.css'
import Croppa from 'vue-croppa'

Vue.use(Croppa)

//Vue-Awesome-Swiper
import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'swiper/dist/css/swiper.css'
Vue.use(VueAwesomeSwiper)

//iconfont
import '@/assets/styles/iconfont.css'
import iconfont from '@/assets/iconfont/iconfont.js'
Vue.use(iconfont)

//vue-scroller
import VueScroller from 'vue-scroller'
Vue.use(VueScroller)

// FastClick.attach(document.body)

Vue.config.productionTip = false

//微信title设置 配合 v-wechat-title="$route.meta.title" 使用
Vue.use(vueWechatTitle)

//引入自定义方法
import common from "@/function/common.js"
Vue.prototype.common = common

router.beforeEach((to, from, next) => {
  let nowtime = new Date().getTime()

  //特殊页面不需要登录的
  if(to.path == '/share' || to.path == '/Detail'){
    next()
    return false
  }
  let userInfo = common.getUserInfo()
  // console.log(userInfo)

  //用户已经登录使用后退返回授权页，默认回到首页
  if(userInfo != null  && to.path == '/author') {
    //如果上次登录时间过期 两个小时
    if(nowtime - userInfo.lastLoginTime >= 7200000){
      next()
      return false
    }
    next('/')
    return false
  }

  //用户第一次进入项目 没有登录openid和用户信息
  if(userInfo == null && to.path != '/author') {
    common.setCookie('beforeLoginUrl', to.fullPath)
    next('/author')
    return false
  }

  // 用户有登录信息，但是没有关注 跳过去关注
  if(userInfo != null && to.path != '/author') {
    if(userInfo.subscribe == 0){
      next('/share')
      return false
    }
    //如果上次登录时间过期 两个小时
    if(nowtime - userInfo.lastLoginTime >= 7200000){
      next('/author')
      return false
    }
  }
  next()

})

/* eslint-disable no-new */
new Vue({
  store,
  router,
  render: h => h(App)
}).$mount('#app-box')
